package com.bige.mall.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.bige.common.annotation.Log;
import com.bige.common.core.controller.BaseController;
import com.bige.common.core.domain.AjaxResult;
import com.bige.common.enums.BusinessType;
import com.bige.mall.domain.MallShopCard;
import com.bige.mall.service.IMallShopCardService;
import com.bige.common.utils.poi.ExcelUtil;
import com.bige.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 购物卡Controller
 * 
 * @author bige
 * @date 2022-01-23
 */
@Api(tags = "购物卡信息管理")
@RestController
@RequestMapping("/mall/shopCard")
public class MallShopCardController extends BaseController
{
    @Autowired
    private IMallShopCardService mallShopCardService;

    /**
     * 查询购物卡列表
     */
    @ApiOperation("查询购物卡列表")
    @PreAuthorize("@ss.hasPermi('mall:shopCard:list')")
    @GetMapping("/list")
    public TableDataInfo list(MallShopCard mallShopCard)
    {
        startPage();
        List<MallShopCard> list = mallShopCardService.selectMallShopCardList(mallShopCard);
        return getDataTable(list);
    }

    /**
     * 导出购物卡列表
     */
    @ApiOperation("导出购物卡列表")
    @PreAuthorize("@ss.hasPermi('mall:shopCard:export')")
    @Log(title = "购物卡", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MallShopCard mallShopCard)
    {
        List<MallShopCard> list = mallShopCardService.selectMallShopCardList(mallShopCard);
        ExcelUtil<MallShopCard> util = new ExcelUtil<MallShopCard>(MallShopCard.class);
        util.exportExcel(response, list, "购物卡数据");
    }

    /**
     * 获取购物卡详细信息
     */
    @ApiOperation("获取购物卡详细信息")
    @PreAuthorize("@ss.hasPermi('mall:shopCard:query')")
    @GetMapping(value = "/{shopId}")
    public AjaxResult getInfo(@PathVariable("shopId") Long shopId)
    {
        return AjaxResult.success(mallShopCardService.selectMallShopCardByShopId(shopId));
    }

    /**
     * 新增购物卡
     */
    @ApiOperation("新增购物卡")
    @PreAuthorize("@ss.hasPermi('mall:shopCard:add')")
    @Log(title = "购物卡", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallShopCard mallShopCard)
    {
        return toAjax(mallShopCardService.insertMallShopCard(mallShopCard));
    }

    /**
     * 修改购物卡
     */
    @ApiOperation("修改购物卡")
    @PreAuthorize("@ss.hasPermi('mall:shopCard:edit')")
    @Log(title = "购物卡", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallShopCard mallShopCard)
    {
        return toAjax(mallShopCardService.updateMallShopCard(mallShopCard));
    }

    /**
     * 删除购物卡
     */
    @ApiOperation("删除购物卡")
    @PreAuthorize("@ss.hasPermi('mall:shopCard:remove')")
    @Log(title = "购物卡", businessType = BusinessType.DELETE)
	@DeleteMapping("/{shopIds}")
    public AjaxResult remove(@PathVariable Long[] shopIds)
    {
        return toAjax(mallShopCardService.deleteMallShopCardByShopIds(shopIds));
    }
}
